package me.zixing.timer.core;

import java.io.FileOutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Vector;

/**
 * Created by bingh on 2017/10/22.
 */
public class TimeSetUtil {
    private static Properties properties = new Properties();

    public static List<String> list = new ArrayList<>(6);

    public volatile static int index;

    static{
        try{
            properties.load(TimeSetUtil.class.getClassLoader().getResourceAsStream("time.properties"));
            list.add(0,"0");
            list.add(1,"0");
            list.add(2,"0");
            list.add(3,"0");
            list.add(4,"0");
            list.add(5,"0");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void saveInputKey(String numKey){
        list.add(index++,numKey);
    }

    public static void setTimeToProperties(){
        long hourToLong = (Integer.parseInt(list.get(0)+list.get(1))) * 3600000;
        long minuteToLong = (Integer.parseInt(list.get(2)+list.get(3))) * 60000;
        long secLong = (Integer.parseInt(list.get(4)+list.get(5))) * 1000;
        properties.setProperty("timeLong",(hourToLong + minuteToLong + secLong) + "");

        try{
            FileOutputStream fos = new FileOutputStream(System.getProperty("user.home")+"/time.properties");
            properties.store(fos,"");
            fos.flush();
            fos.close();

        }catch (Exception e){
            e.printStackTrace();
        }



    }

    public static void clear(){
        for(int i=0;i<index;i++){
            list.set(i,"0");
        }
        index = 0;
    }

}
